	<h2>
	<strong>Phụ Lục Hợp Đồng</strong></h2>

<script type="text/javascript" src="../scripts/date.js"></script>
	<script type="text/javascript">
	function PhuLucHopDongXuLy()
	{
		document.getElementById("formgui").action = "index.php?do=phuluchopdong_xuly";
		document.formgui.submit(); 
	}
	function checkRutLai(){
	 	var xmlHttp;
	 	var MaPhuLuc = document.getElementById('MaPhuLuc').value;
	    if(window.XMLHttpRequest){
	        xmlHttp = new XMLHttpRequest;
	    }
	    else if(window.ActiveXObject){
	        xmlHttp = new ActiveXObject('Microsoft.XMLHTTP');
	    }
	    
	    xmlHttp.onreadystatechange = function(){
	        if(xmlHttp.readyState == 4){
		        var NgayLanhLai = document.getElementById('NgayLanhLai').value;
		        var NgayDenHan = document.getElementById('NgayDenHan2').value;
	        	if ((new Date(NgayDenHan).getTime() > new Date(NgayLanhLai).getTime())) {
	                alert("Chưa đến ngày lãnh lãi. Ngày lãnh lãi phải >= "+NgayDenHan);
	                document.getElementById("rutlai").checked = false;
	                var TienLai = xmlHttp.responseText;
	        		//document.getElementById('LaiChoVay').value = TienLai;
	        		//document.getElementById('SoTienTraGoc').value = TienLai;
	        	}
	        	else {
	        		var TienLai = xmlHttp.responseText;
	        		document.getElementById('LaiChoVay').value = TienLai;
	        		document.getElementById('SoTienTraGoc').value = TienLai;
	        	}
	        }
	    }
	    xmlHttp.open('GET', '../adm/nhanvien/sotietkiem/checkrutlai.php?maphuluc='+MaPhuLuc, true);
	    xmlHttp.send(null);
	}
	function checkRutHoanToan(){
	 	var xmlHttp;
	 	var MaPhuLuc = document.getElementById('MaPhuLuc').value;
	    if(window.XMLHttpRequest){
	        xmlHttp = new XMLHttpRequest;
	    }
	    else if(window.ActiveXObject){
	        xmlHttp = new ActiveXObject('Microsoft.XMLHTTP');
	    }
	    
	    xmlHttp.onreadystatechange = function(){
	        if(xmlHttp.readyState == 4){
		        var NgayLanhLai = document.getElementById('NgayLanhLai').value;
		        var NgayDenHan = document.getElementById('NgayDenHan2').value;
	        	if ((new Date(NgayDenHan).getTime() > new Date(NgayLanhLai).getTime())) {
	                alert("Chưa đến ngày để có thể rút hoàn toàn. Ngày rút phải >= "+NgayDenHan);
	              	document.getElementById("ruthoantoan").checked = false;
	                var TienLai = xmlHttp.responseText;
	        		//document.getElementById('LaiChoVay').value = TienLai;
	        		//document.getElementById('SoTienTraGoc').value = Number(TienLai) + Number(document.getElementById('SoTienGui').value);
	        	}
	        	else {
	        		var TienLai = xmlHttp.responseText;
	        		document.getElementById('LaiChoVay').value = TienLai;
	        		document.getElementById('SoTienTraGoc').value = Number(TienLai) + Number(document.getElementById('SoTienGui').value);
	        	}
	        }
	    }
	    xmlHttp.open('GET', '../adm/nhanvien/sotietkiem/checkruthoantoan.php?maphuluc='+MaPhuLuc, true);
	    xmlHttp.send(null);
	}
</script>
<?php
	$hopdongtindung = new hopdongtindungbs();
	$hopdongtindung->SoKheUoc = $_GET["id"];
	$danhsach = $hopdongtindung->LayDanhSach();
?>

<form id="formgui" enctype="multipart/form-data" name="formgui"  method="post" action="index.php?do=inphieuthuno&id=<?php echo $_GET["id"];?>" onsubmit="return checkPostArtForm(this);">
<table style="width:950px; margin-left: 10px; table-layout: fixed;">
		<tr>
			<td style="width:15px;padding-top:10px;">
	        	<label for="maphuluc">Chọn giao dịch:</label>&nbsp<span class="requirefield">*</span> 
	        </td>
	        <td style="width:15px;padding-top:10px;">
	            <input name="loaithutien" type="radio" id="thulai" value="thulai" onclick="checkThuLai();"/>Thu lãi
	        </td>
	        <td style="width:15px;padding-top:10px;">
				<input name="loaithutien" type="radio" id="thuno" onclick="checkThuNo();" value="thuno"/>Thu nợ
	        </td>
		</tr>
		<p class="requirefields">(*): Các trường bắt buộc phải có.</p>
</table>
<br/>
<table style="width:950px; margin-left: 10px; table-layout: fixed;">	
		<?php 	
				$tstc = new taisanthechapbs();
				$tstc->SoHDTC = $danhsach[0]["SoHDTC"];
				$dstaisanthechap = $tstc->LayDanhSach();
			?>
			<?php 	
				$htv = new hinhthucvaybs();
				$htv->MaHinhThucVay = $hinhthucvay[0]["MaHinhThucVay"];
				$dshinhthucvay = $htv->LayDanhSach();
			?>
			<?php 
				$khachhang = new khachhangbs();
				$khachhang->MaKH = $dstaisanthechap[0]["MaKH"];
				$dskhachhang = $khachhang->LayDanhSach();
			?>
		<tr>
			<td style="width:20px;padding-top:10px;">
	        	<label for="sokheuoc">Số khế ước:</label>
	        </td>
	        <td style="width:60px;padding-top:10px;">
	           	<input readonly="readonly" tabindex="1" type="text" id="SoKheUoc" name="SoKheUoc" class="txt" size="54" value="<?php echo $danhsach[0]["SoKheUoc"];?>"/>   
	        </td>
	        <td style="width:15px;padding-top:10px;">

	        </td>
	        <td style="width:60px;padding-top:10px;">

	        </td>
		</tr>
		<tr>
			<td style="padding-top:10px;">
	        	<label for="tenkhachhang">Khách hàng:</label>
	        </td>	       
			<td style="padding-top:10px;">
				<input readonly="readonly" tabindex="1" type="text" id="TenKhachHang" name="TenKhachHang" class="txt" size="12" value="<?php echo $dskhachhang[0]['Ho'] . " ". $dskhachhang[0]['Ten'];?>" onchange="ChuyenMaKhachHang(this.value);GetThongTinKhachHang(this.value);"/>
			</td>
			<td style="padding-top:10px;">
	        	<label for="makhachhang">Tài khoản:</label>      	
	        </td>
			 <td style="padding-top:10px;">
	        	<input readonly="readonly" tabindex="1" type="text" id="MaKH" name="MaKH" class="txt" size="12" value="<?php echo $dskhachhang[0]['MaKH'];?>" />
	        </td>
		</tr>	
		<tr>
			<td style="padding-top:10px;">
	        	<label for="ngaymoso">Ngày mở sổ:</label> 
	        </td>
			<td style="padding-top:10px;">
				<input readonly="readonly" tabindex="1" type="text" id="NgayMoSo" name="NgayMoSo" class="txt" size="12" value="<?php echo $danhsach[0]["NgayLapHopDong"];?>" />
			</td>
			<td style="padding-top:10px;">
				<label for="ngaydenhan">Ngày đến hạn:</label>
	        </td>
			<td style="padding-top:10px;">
				<input type="hidden" id="NgayDenHan2" value="<?php echo $danhsach[0]["NgayDenHan"];?>"/>
				<input readonly="readonly" tabindex="1" type="text" id="NgayDenHan" name="NgayDenHan" class="txt" size="12" value="<?php echo $danhsach[0]["NgayDenHan"];?>" />
	        </td>
		</tr>
		<tr>
			<td style="padding-top:10px;">
	        	<label for="hinhthucvay">Hình thức vay:</label>
	        </td>
			<td style="padding-top:10px;">
				<?php
					$kyhantra = new kyhantrabs();
					$kyhantra->MaKyHanTra =  $danhsach[0]['MaKyHanTra'];
					$dskyhantra = $kyhantra->LayDanhSach();
					$hinhthucvay = new hinhthucvaybs();
					$hinhthucvay->MaHinhThucVay =  $dskyhantra[0]['MaHinhThucVay'];
					$dshinhthucvay = $hinhthucvay->LayDanhSach();
				?>
				<input readonly="readonly" tabindex="1" type="text" name="HinhThucVay" class="txt" value="<?php echo $dshinhthucvay[0]["TenHinhThucVay"];?>" />   		
			</td>
			<td style="padding-top:15px;">
	        	<label for="thoihanvay">Số tháng cho vay:</label>  
	        </td>
			<td style="padding-top:15px;">
				<input readonly="readonly" tabindex="1" type="text" name="SoThangVay" class="txt" value="<?php echo $danhsach[0]["SoThangVay"];?>" />   
			</td>
		</tr>
		<tr>
			<td style="padding-top:15px;">
	        	<label for="laisuatchovay">Lãi suất cho vay:</label> 
	        </td>
	        <td style="padding-top:15px;">
	        	<input readonly="readonly" tabindex="1" type="text" name="LaiSuatVay" class="txt" value="<?php echo $dshinhthucvay[0]["LaiSuatVay"];?>" />   
	    	</td>
			<td style="padding-top:10px;">
	        	<label for="sotienchovay">Số tiền cho vay:</label>
	        </td>
			<td style="padding-top:10px;">
				<input readonly="readonly" tabindex="1" type="text" name="SoTienVay" class="txt" value="<?php echo $danhsach[0]["SoTienVay"];?>" />   
			</td>
	    </tr>	
		<tr>
			<td colspan="0">
			<hr>
			</td>
		</tr>
		<tr>
			<td style="width:15px;padding-top:10px;">
	        	<label for="ngaytra">Ngày trả:</label>
	        </td>
	        <?php 
		        date_default_timezone_set('Asia/Ho_Chi_Minh');
	        ?>
			<td style="padding-top:10px;">
				<input readonly="readonly" tabindex="1" type="text" id="NgayTra" name="NgayTra" class="txt" size="12" value="<?php echo date("Y-m-d", time());?>" />
			</td>             
		</tr>
		<tr>
			<td style="width:15px;padding-top:10px;">
	        	<label for="sotientragoc">Số tiền trả gốc:</label>
	        </td>
	        <td style="width:60px;padding-top:10px;">
	            <input tabindex="1" type="text" id="SoTienTraGoc" name="SoTienTraGoc" class="txt" " />
	        </td>
	        <td style="width:15px;padding-top:10px;">
				<label for="sotientralai">Số tiền trả lãi:</label>
	        </td>
	        <td style="width:60px;padding-top:10px;">
				<input readonly="readonly" tabindex="1" type="text" id="SoTienTraLai" name="SoTienTraLai" class="txt" />
	        </td>    
		</tr>
		<tr>
			<td style="width:15px;padding-top:10px;">
	        	<label for="dunotronghan">Dư nợ trong hạn:</label>
	        </td>
	        <td style="width:60px;padding-top:10px;">
	            <input readonly="readonly" tabindex="1" type="text" id="DuNoTrongHan" name="DuNoTrongHan" class="txt" />   
	        </td>
	        <td style="width:15px;padding-top:10px;">
				<label for="sotienquahan">Số tiền quá hạn:</label>
	        </td>
	        <td style="width:60px;padding-top:10px;">
				<input readonly="readonly" tabindex="1" type="text" id="SoTienQuaHan" name="SoTienQuaHan" class="txt"/>   
	        </td>    
		</tr>
		
		<tr>
			<td colspan="0">
			<hr>
			</td>
		</tr>
		<tr>
			<td style="width:15px;padding-top:10px;">
	        	<label for="sobuttoan">Số bút toán:</label>
	        </td>
	        <td style="width:60px;padding-top:10px;">
	            <input readonly="readonly" tabindex="1" type="text" name="SoButToan" class="txt" size="54" value="<?php include '../adm/nhanvien/sotietkiem/getsobuttoan.php';?>"/>   
	        </td>
			<td style="width:15px;padding-top:10px;">
	        	<label for="nhanvienlapso">Nhân viên lập sổ:</label>
	        </td>
	        <td style="width:60px;padding-top:10px;">
	        	<?php 
	        		$nguoidung = new nguoidungbs();
	        		$nguoidung->MaNguoiDung = $_SESSION["MaND"];
	        		$danhsach = $nguoidung->LayDanhSach();
	        		$HoTen = $danhsach[0]["Ho"]." ".$danhsach[0]["Ten"];
	        	?>
	        	<input type="hidden" name="MaNhanVien" value="<?php echo $danhsach[0]['MaNguoiDung'] ?>"/>
	            <input readonly="readonly" tabindex="1" type="text" name="TenNhanVien" class="txt" size="54" value="<?php echo $HoTen; ?>"/>   
	        </td>
	       </tr>
</table>

<br/>
<br/>
<p align="center">
	<a href="javascript:PhuLucHopDongXuLy();" class="button small blue">Hoàn tất</a>
	&nbsp &nbsp &nbsp	
	<input type="submit" class="button small blue" value="In phiếu thu nợ"/>
	&nbsp &nbsp &nbsp
	<a href="index.php?do=inphieuthulai&id=<?php echo $_GET["id"];?>" class="button small blue">In phiếu thu lãi</a>
</p>
</form>

<?php
	if(isset($_SESSION["LoiThemPhuLucHopDong"]))
	{
		echo $_SESSION["LoiThemPhuLucHopDong"];
		unset($_SESSION["LoiThemPhuLucHopDong"]);
	}
?>

<script type="text/javascript">
function checkPostArtForm(frm)
{
	var loairuttien = document.getElementsByName("loaithutien");
	<?php 
		if(isset($_GET["sotientra"]))
			echo "return true";
	?>
	if(!loaithutien.item(0).checked && !loaithutien.item(1).checked)
	{
		alert('Bạn chưa chọn loại thu tiền');
		return false;
	}
	return true;
}
</script>

